from sqlalchemy import Column, Integer, String, Float, DateTime, Date
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime

Base = declarative_base()

class ModelEval(Base):
    """模型评估表"""
    __tablename__ = 'model_eval'
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    model = Column(String(32), nullable=False, comment='模型名称')
    train_dt = Column(Date, nullable=False, comment='训练日期')
    mae = Column(Float, nullable=True, comment='平均绝对误差')
    rmse = Column(Float, nullable=True, comment='均方根误差')
    mape = Column(Float, nullable=True, comment='平均绝对百分比误差')
    r2 = Column(Float, nullable=True, comment='决定系数')
    max_err = Column(Float, nullable=True, comment='最大误差')
    created_at = Column(DateTime, nullable=True, default=datetime.now, comment='评估时间')
    
    def __repr__(self):
        return f"<ModelEval(model='{self.model}', mae={self.mae}, r2={self.r2})>" 